home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / cm / cmtbdict.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-06  |  3.8 KB  |  138 lines

  1. // CmTBDict.cc
  2. // -----------------------------------------------------------------
  3. // Compendium - C++ Container Class Library
  4. // Copyright (C) 1992-1994, Glenn M. Poorman, All rights reserved
  5. // -----------------------------------------------------------------
  6. // BTree dictionary template implementation.
  7. // -----------------------------------------------------------------
  8.  
  9.  
  10. // "CmTBTreeDictionary" is the default dictionary constructor.
  11. //
  12. template <class T, class O>
  13. CmTBTreeDictionary<T,O>::CmTBTreeDictionary(unsigned order)
  14.                        : CmTBTree< CmTAssociation<T, O> >(order)
  15. {}
  16.  
  17.  
  18. // "CmTBTreeDictionary" is the dictionary copy constructor.
  19. //
  20. template <class T, class O>
  21. CmTBTreeDictionary<T,O>::CmTBTreeDictionary(const CmTBTreeDictionary<T,O>& Tr)
  22.                        : CmTBTree< CmTAssociation<T, O> >(Tr)
  23. {}
  24.  
  25.  
  26. // "=" assignment operator copies the specified dictionary into this
  27. // dictionary.
  28. //
  29. template <class T, class O> CmTBTreeDictionary<T,O>&
  30. CmTBTreeDictionary<T,O>::operator=(const CmTBTreeDictionary<T,O>& Tr)
  31. {
  32.   return (CmTBTreeDictionary<T,O>&)
  33.           CmTBTree< CmTAssociation<T, O> >::operator=(Tr);
  34. }
  35.  
  36.  
  37. // "addKey" adds an association with the specified key to the dictionary.
  38. //
  39. template <class T, class O>
  40. Bool CmTBTreeDictionary<T,O>::addKey(const T& rKey)
  41. {
  42.   return add(CmTAssociation<T,O>(rKey));
  43. }
  44.  
  45.  
  46. // "addKeyAndObject" adds an association with the specified key and the
  47. // specified object to the dictionary.
  48. //
  49. template <class T, class O>
  50. Bool CmTBTreeDictionary<T,O>::addKeyAndObject(const T& rKey, const O& rObj)
  51. {
  52.   return add(CmTAssociation<T,O>(rKey, rObj));
  53. }
  54.  
  55.  
  56. // "addAssoc" adds the specified association to the dictionary.
  57. //
  58. template <class T, class O>
  59. Bool CmTBTreeDictionary<T,O>::addAssoc(const CmTAssociation<T,O>& rAssoc)
  60. {
  61.   return add(rAssoc);
  62. }
  63.  
  64.  
  65. // "removeKey" removes the first association containing the specified
  66. // key from the dictionary.
  67. //
  68. template <class T, class O>
  69. Bool CmTBTreeDictionary<T,O>::removeKey(const T& rKey)
  70. {
  71.   return remove(CmTAssociation<T,O>(rKey));
  72. }
  73.  
  74.  
  75. // "lookupKey" returns a copy of the key out of the first occurrence of
  76. // an association containing the specified key.
  77. //
  78. template <class T, class O>
  79. const T& CmTBTreeDictionary<T,O>::lookupKey(const T& rKey) const
  80. {
  81.   CmTAssociation<T,O> assoc = lookup(CmTAssociation<T,O>(rKey));
  82.   return assoc.key();
  83. }
  84.  
  85.  
  86. // "lookupObject" returns a copy of the object out of the first occurrence
  87. // of an association containing the specified key.
  88. //
  89. template <class T, class O>
  90. const O& CmTBTreeDictionary<T,O>::lookupObject(const T& rKey) const
  91. {
  92.   CmTAssociation<T,O> assoc = lookup(CmTAssociation<T,O>(rKey));
  93.   return assoc.object();
  94. }
  95.  
  96.  
  97. // "lookupAssoc" returns a copy of the first occurrence of an association
  98. // containing the specified key.
  99. //
  100. template <class T, class O> const CmTAssociation<T,O>&
  101. CmTBTreeDictionary<T,O>::lookupAssoc(const T& rKey) const
  102. {
  103.   return lookup(CmTAssociation<T,O>(rKey));
  104. }
  105.  
  106.  
  107. // "replace" finds the first occurrence of an association containing the
  108. // specified key and replaces the object value.
  109. //
  110. template <class T, class O>
  111. Bool CmTBTreeDictionary<T,O>::replace(const T& rKey, const O& rObj)
  112. {
  113.   if (remove(CmTAssociation<T,O>(rKey)))
  114.     return addKeyAndObject(rKey, rObj);
  115.   else
  116.     return FALSE;
  117. }
  118.  
  119.  
  120. // "containsKey" returns TRUE if the dictionary contains an association
  121. // with the specified key.
  122. //
  123. template <class T, class O>
  124. Bool CmTBTreeDictionary<T,O>::containsKey(const T& rKey) const
  125. {
  126.   return contains(CmTAssociation<T,O>(rKey));
  127. }
  128.  
  129.  
  130. // "occurrencesOfKey" returns the number of associations containing
  131. // the specified key.
  132. //
  133. template <class T, class O>
  134. unsigned CmTBTreeDictionary<T,O>::occurrencesOfKey(const T& rKey) const
  135. {
  136.   return occurrences(CmTAssociation<T,O>(rKey));
  137. }
  138.